package com.lottery.im.module.chat.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.MyApplication;
import com.lottery.im.R;
import com.lottery.im.module.tim.model.FriendProfile;
import com.lottery.im.util.transformations.CropCircleTransformation;
import java.util.List;

public class CreateGroupFriendAdapter extends BaseQuickAdapter<FriendProfile, BaseViewHolder> {

  private List<String> mSelectIds;

  public CreateGroupFriendAdapter(@Nullable List<FriendProfile> data, List<String> selectIds) {
    super(R.layout.item_group_member_list, data);
    this.mSelectIds = selectIds;
  }

  @Override protected void convert(BaseViewHolder helper, FriendProfile item) {

    if (mSelectIds.contains(item.getIdentify())) {
      helper.setImageResource(R.id.iv_status, R.drawable.icon_xz_selected);
    } else {
      helper.setImageResource(R.id.iv_status, R.drawable.icon_xz_nomal);
    }

    if (item.getIdentify().equals(MyApplication.getInstance().getThirdAccId())
        || item.getIdentify().equals(MyApplication.getInstance().getUserInfo().getQqServiceName())
        || item.getIdentify()
        .equals(MyApplication.getInstance().getUserInfo().getQqFeedBackName())) {
      helper.setImageResource(R.id.iv_status, R.drawable.icon_xz_unenable);
    }

    ImageView ivPortrait = helper.getView(R.id.iv_portrait);
    Glide.with(mContext)
        .load(item.getAvatarUrl())
        .apply(new RequestOptions()
            .bitmapTransform(new CropCircleTransformation())
            .placeholder(R.drawable.icon_conversation_de)
            .error(R.drawable.icon_conversation_de))
        .into(ivPortrait);

    helper.setText(R.id.tv_name, item.getNickName());
  }

  public void setSelectIds(List<String> selectIds, int position) {
    mSelectIds = selectIds;
    notifyItemChanged(position);
  }
}
